import { defineStore } from "pinia";
import Cookies from "js-cookie";
export const useInfoStore = defineStore('userInfo', {
    // 存储全局状态
    // 必须是箭头函数：为了在服务端渲染的时候避免交叉请求导致数据状态污染
    state: () => ({
        token: null,
        user: null,
        contactId: null,
        errMSg: null
    }),
    // 用来封装计算属性，有缓存功能，类似于computed
    getters: {
        getNum(state) {
            return state.count + 1
        }
    },
    // 编辑业务逻辑，类似methods
    actions: {
        saveToken(token) {
            this.token = token,
                Cookies.set("Token", token)
        },
        saveUser(user) {
            this.user = user
            sessionStorage.setItem("user", JSON.stringify(user))
        }
    }
})